*******************************************************************************
* GSS.
* Reduce inequality and class.
* Separate models for each survey year.
*******************************************************************************

* Collect all frame names.
frames dir
local frn = r(frames)
local defn = "default"
local frn2: list frn- defn
* Drop frames that aren't default.
foreach fname of local frn2 {
	frame drop `fname'
}

*******************************************************************************
* Full sample.
*******************************************************************************


local varlst1 "pid7 polviews white age female south"

* Objective class.
* EGP 1.
frame copy default coef_ineq_egp1 , replace
frame coef_ineq_egp1 { 
	contract year if (govineq01 != .)
	gen str var = "egp1"
	gen str dv = "Reduce inequality (GSS)"
	gen b = .
	gen ll = .
	gen ul = .
	gen n = .
	levelsof year , local(lst_year)
}

foreach yr of numlist `lst_year' {
	reg govineq01 egp5_1-egp5_4 `varlst1' if year==`yr' 
	matrix EGP = r(table)
	frame coef_ineq_egp1 {
		replace b = EGP[1,1] if year == `yr'
		replace ll = EGP[5,1] if year == `yr'
		replace ul = EGP[6,1] if year == `yr'
		replace n = `e(N)' if year == `yr'
	}
}

* EGP 2.
frame copy default coef_ineq_egp2 , replace
frame coef_ineq_egp2 { 
	contract year if (govineq01 != .)
	gen str var = "egp2"
	gen str dv = "Reduce inequality (GSS)"
	gen b = .
	gen ll = .
	gen ul = .
	gen n = .
	levelsof year , local(lst_year)
}

foreach yr of numlist `lst_year' {
	reg govineq01 egp5_1-egp5_4 `varlst1' if year==`yr'
	matrix EGP = r(table)
	frame coef_ineq_egp2 {
		replace b = EGP[1,2] if year == `yr'
		replace ll = EGP[5,2] if year == `yr'
		replace ul = EGP[6,2] if year == `yr'
		replace n = `e(N)' if year == `yr'
	}
}


* All other class variables.
foreach v in subclass inc5 edu5 {
frame copy default coef_ineq_`v' , replace
frame coef_ineq_`v' { 
	contract year if (govineq01 != .)
	gen str var = "`v'"
	gen str dv = "Reduce inequality (GSS)"
	gen b = .
	gen ll = .
	gen ul = .
	gen n = .
	levelsof year , local(lst_year)
}

foreach yr of numlist `lst_year' {
	reg govineq01 `v' `varlst1' if year==`yr'
	matrix R = r(table)
	frame coef_ineq_`v' {
		replace b = R[1,1] if year == `yr'
		replace ll = R[5,1] if year == `yr'
		replace ul = R[6,1] if year == `yr'
		replace n = `e(N)' if year == `yr'
	}
}
}


*******************************************************************************
* GSS.
* Culture policy and class.
* Separate models for each survey year.
*******************************************************************************

*******************************************************************************
* Full sample.
*******************************************************************************

local varlst1 "pid7 polviews white age female south"

* Objective class.
* EGP 1.
frame copy default coef_cult_egp1 , replace
frame coef_cult_egp1 { 
	contract year if (culpol01 != .)
	gen str var = "egp1"
	gen str dv = "Culture policy (GSS)"
	gen b = .
	gen ll = .
	gen ul = .
	gen n = .
	levelsof year , local(lst_year)
}

foreach yr of numlist `lst_year' {
	reg culpol01 egp5_1-egp5_4 `varlst1' if year==`yr' 
	matrix EGP = r(table)
	frame coef_cult_egp1 {
		replace b = EGP[1,1] if year == `yr'
		replace ll = EGP[5,1] if year == `yr'
		replace ul = EGP[6,1] if year == `yr'
		replace n = `e(N)' if year == `yr'
	}
}

* EGP 2.
frame copy default coef_cult_egp2 , replace
frame coef_cult_egp2 { 
	contract year if (culpol01 != .)
	gen str var = "egp2"
	gen str dv = "Culture policy (GSS)"
	gen b = .
	gen ll = .
	gen ul = .
	gen n = .
	levelsof year , local(lst_year)
}

foreach yr of numlist `lst_year' {
	reg culpol01 egp5_1-egp5_4 `varlst1' if year==`yr'
	matrix EGP = r(table)
	frame coef_cult_egp2 {
		replace b = EGP[1,2] if year == `yr'
		replace ll = EGP[5,2] if year == `yr'
		replace ul = EGP[6,2] if year == `yr'
		replace n = `e(N)' if year == `yr'
	}
}


* All other class variables.
foreach v in subclass inc5 edu5 {
frame copy default coef_cult_`v' , replace
frame coef_cult_`v' { 
	contract year if (culpol01 != .)
	gen str var = "`v'"
	gen str dv = "Culture policy (GSS)"
	gen b = .
	gen ll = .
	gen ul = .
	gen n = .
	levelsof year , local(lst_year)
}

foreach yr of numlist `lst_year' {
	reg culpol01 `v' `varlst1' if year==`yr'
	matrix R = r(table)
	frame coef_cult_`v' {
		replace b = R[1,1] if year == `yr'
		replace ll = R[5,1] if year == `yr'
		replace ul = R[6,1] if year == `yr'
		replace n = `e(N)' if year == `yr'
	}
}
}


*******************************************************************************
* GSS.
* Race policy and class.
* Separate models for each survey year.
*******************************************************************************

*******************************************************************************
* White respondents only.
*******************************************************************************

local varlst2 "pid7 polviews age female south"

* Objective class.
* EGP 1.
frame copy default coef_race_egp1 , replace
frame coef_race_egp1 { 
	contract year if (racepol01 != .)
	gen str var = "egp1"
	gen str dv = "Race policy (GSS)"
	gen b = .
	gen ll = .
	gen ul = .
	gen n = .
	levelsof year , local(lst_year)
}

foreach yr of numlist `lst_year' {
	reg racepol01 egp5_1-egp5_4 `varlst2' if year==`yr' & white==1
	matrix EGP = r(table)
	frame coef_race_egp1 {
		replace b = EGP[1,1] if year == `yr'
		replace ll = EGP[5,1] if year == `yr'
		replace ul = EGP[6,1] if year == `yr'
		replace n = `e(N)' if year == `yr'
	}
}

* EGP 2.
frame copy default coef_race_egp2 , replace
frame coef_race_egp2 { 
	contract year if (racepol01 != .)
	gen str var = "egp2"
	gen str dv = "Race policy (GSS)"
	gen b = .
	gen ll = .
	gen ul = .
	gen n = .
	levelsof year , local(lst_year)
}

foreach yr of numlist `lst_year' {
	reg racepol01 egp5_1-egp5_4 `varlst2' if year==`yr' & white==1
	matrix EGP = r(table)
	frame coef_race_egp2 {
		replace b = EGP[1,2] if year == `yr'
		replace ll = EGP[5,2] if year == `yr'
		replace ul = EGP[6,2] if year == `yr'
		replace n = `e(N)' if year == `yr'
	}
}


* All other class variables.
foreach v in subclass inc5 edu5 {
frame copy default coef_race_`v' , replace
frame coef_race_`v' { 
	contract year if (racepol01 != .)
	gen str var = "`v'"
	gen str dv = "Race policy (GSS)"
	gen b = .
	gen ll = .
	gen ul = .
	gen n = .
	levelsof year , local(lst_year)
}

foreach yr of numlist `lst_year' {
	reg racepol01 `v' `varlst2' if year==`yr' & white==1
	matrix R = r(table)
	frame coef_race_`v' {
		replace b = R[1,1] if year == `yr'
		replace ll = R[5,1] if year == `yr'
		replace ul = R[6,1] if year == `yr'
		replace n = `e(N)' if year == `yr'
	}
}
}


*******************************************************************************
* GSS.
* Vote choice and class.
* Separate models for each survey year.
*******************************************************************************

*******************************************************************************
* Full sample.
*******************************************************************************


local varlst1 "pid7 polviews white age female south"

* Objective class.
* EGP 1.
frame copy default coef_vote1_egp1 , replace
frame coef_vote1_egp1 { 
	contract year if (demvote != . & year != 1973)
	gen str var = "egp1"
	gen str dv = "Vote Dem. (GSS)"
	gen b = .
	gen ll = .
	gen ul = .
	gen n = .
	levelsof year , local(lst_year)
}

foreach yr of numlist `lst_year' {
	logit demvote egp5_1-egp5_4 `varlst1' if year==`yr' 
	matrix EGP = r(table)
	frame coef_vote1_egp1 {
		replace b = EGP[1,1] if year == `yr'
		replace ll = EGP[5,1] if year == `yr'
		replace ul = EGP[6,1] if year == `yr'
		replace n = `e(N)' if year == `yr'
	}
}

* EGP 2.
frame copy default coef_vote1_egp2 , replace
frame coef_vote1_egp2 { 
	contract year if (demvote != . & year != 1973)
	gen str var = "egp2"
	gen str dv = "Vote Dem. (GSS)"
	gen b = .
	gen ll = .
	gen ul = .
	gen n = .
	levelsof year , local(lst_year)
}

foreach yr of numlist `lst_year' {
	logit demvote egp5_1-egp5_4 `varlst1' if year==`yr'
	matrix EGP = r(table)
	frame coef_vote1_egp2 {
		replace b = EGP[1,2] if year == `yr'
		replace ll = EGP[5,2] if year == `yr'
		replace ul = EGP[6,2] if year == `yr'
		replace n = `e(N)' if year == `yr'
	}
}


* All other class variables.
foreach v in subclass inc5 edu5 {
frame copy default coef_vote1_`v' , replace
frame coef_vote1_`v' { 
	contract year if (demvote != . & year != 1973)
	gen str var = "`v'"
	gen str dv = "Vote Dem. (GSS)"
	gen b = .
	gen ll = .
	gen ul = .
	gen n = .
	levelsof year , local(lst_year)
}

foreach yr of numlist `lst_year' {
	logit demvote `v' `varlst1' if year==`yr'
	matrix R = r(table)
	frame coef_vote1_`v' {
		replace b = R[1,1] if year == `yr'
		replace ll = R[5,1] if year == `yr'
		replace ul = R[6,1] if year == `yr'
		replace n = `e(N)' if year == `yr'
	}
}
}


*******************************************************************************
* GSS.
* Vote choice and policy attitudes.
* Separate models for each survey year.
*******************************************************************************

*******************************************************************************
* Full sample.
*******************************************************************************


local varlst1 "pid7 polviews white age female south"

foreach v in govineq01 culpol01 racepol01 {
frame copy default coef_dvotepol1_`v' , replace
frame coef_dvotepol1_`v' { 
	contract year if (demvote != . & year != 1973 & `v'!=.)
	gen str var = "`v'"
	gen str dv = "Vote Dem. (GSS)"
	gen b = .
	gen ll = .
	gen ul = .
	gen n = .
	levelsof year , local(lst_year)
}

foreach yr of numlist `lst_year' {
	logit demvote `v' `varlst1' if year==`yr'
	matrix R = r(table)
	frame coef_dvotepol1_`v' {
		replace b = R[1,1] if year == `yr'
		replace ll = R[5,1] if year == `yr'
		replace ul = R[6,1] if year == `yr'
		replace n = `e(N)' if year == `yr'
	}
}
}



* Combine frames.
* Collect all frame names.
frames dir
local frn = r(frames)
local defn = "default"
local frn2: list frn- defn

* New frame for append.
frame create sepmods_coef_gss

foreach fname of local frn2 {
	frame `fname' {
		tempfile `fname'
		save ``fname'', replace
	}
	frame sepmods_coef_gss : append using ``fname''
}

* Recode some labels.
frame sepmods_coef_gss {
	gen str model = "Model for each year"
	replace var = "Upper Class" if var == "egp1"
	replace var = "Upper Mid. Class" if var == "egp2"
	replace var = "Subjective Class" if var == "subclass"
	replace var = "Income" if var == "inc5"
	replace var = "Education" if var == "edu5"
	replace var = "Reduce Inequality" if var == "govineq01"
	replace var = "Culture Policy" if var == "culpol01"
	replace var = "Race Policy" if var == "racepol01"
	save "results/coef_gss_sepmods.dta", replace
}

* Drop frames.
foreach fname of local frn2 {
	frame drop `fname'
}
frame drop sepmods_coef_gss


